'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: queue_entity.py
* @Time: 2025/10/10
* @All Rights Reserve By Brtc
'''
from enum import Enum
from uuid import UUID
from pydantic import BaseModel, Field

from internal.entity.conversation_entity import MessageStatus


class QueueEvent(str, Enum):
    """队列事件枚举类型"""
    LONG_TERM_MEMORY_RECALL = "long_term_memory_recall" # 长期记忆事件
    AGENT_THOUGHT = "agent_thought" # 智能体思考事件
    AGENT_MESSAGE = "agent_message"# 智能体消息事件
    AGENT_ACTION = "agent_action" #智能体输出事件
    DATASET_RETRIEVAL = "dataset_retrieval" #知识库检索事件
    AGENT_END = "agent_end" # 智能体结束事件
    STOP = "stop"  #  智能体输出停止
    ERROR= "error" #  智能体报错
    TIMEOUT = "timeout" # 超时
    PING = "ping" # ping 事件


class AgentThought(BaseModel):
    """智能体队列事件模型"""
    id:UUID
    task_id:UUID
    #事件相关信息
    event:QueueEvent
    thought:str = "" # 思考内容
    observation:str="" # 观察内容
    #工具相关信息
    tool:str = "" # 工具调用信息
    tool_input:dict = Field(default_factory=dict) # 工具的输入
    #消息相关的数据
    message:list[dict] = Field(default_factory=dict) # 消息列表
    message_token_count:int  = 0 # 消息花费的总token
    message_unit_price:float = 0 #单价
    message_price_unit:float = 0 #计算价格的币种
    #答案相关的数据
    answer:str = ""
    answer_token_count:int = 0
    answer_unit_price:float = 0.0
    answer_price_unit:float = 0.0
    #Agent统计相关
    total_token_count:int = 0 #总token 消耗数量
    total_price:float = 0.0 # 总的花费
    latency:float = 0.0 # 整个耗时

class AgentResult(BaseModel):
    #用户的原始问题
    query:str = ""
    # 消息相关的数据
    message: list[dict] = Field(default_factory=dict)  # 消息列表
    message_token_count: int = 0  # 消息花费的总token
    message_unit_price: float = 0  # 单价
    message_price_unit: float = 0  # 计算价格的币种
    # 答案相关的数据
    answer: str = ""
    answer_token_count: int = 0
    answer_unit_price: float = 0.0
    answer_price_unit: float = 0.0
    # Agent统计相关
    total_token_count: int = 0  # 总token 消耗数量
    total_price: float = 0.0  # 总的花费
    latency: float = 0.0  # 整个耗时

    status:str = MessageStatus.NORMAL #消息的状态
    error:str = "" # 错误消息

    agent_thoughts:list[AgentThought] = Field(default_factory=list) # 问题输出的整个 步骤







